package com.tiecode.plugin.regex.util;

import com.tiecode.plugin.regex.editor.RegexEntity;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class RegexTestUtils {
    public static String doTest(RegexEntity entity) {
        if (entity == null) {
            return null;
        }
        String result;
        try {
            Matcher matcher = Pattern.compile(entity.regex).matcher(entity.content);
            result = "";
            while (matcher.find()) {
                result += matcher.group();
            }
        } catch (Exception e) {
            result = e.getMessage();
        }
        return result;
    }
}
